#include "Common.h"
#include "FinInvestment.h"

extern std::vector<InvestmentOption> investmentOptionVector;
extern double **covarianceArray;

/*
 * This file is part of FinVis.
 *
 * FinVis is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * FinVis is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with FinVis.  If not, see <http://www.gnu.org/licenses/>
 *
 * @author Stephen Rudolph
 */

/*
 * Constructors, destructor, and assignment operator
 */
FinInvestment::FinInvestment()
    : m_title("")
    , m_principal(0)
    , m_startDate(QDate(START_YEAR, 1, 1))
    , m_investmentOptionVectorIndex(0)
    , m_orderIndex(-1)
{
}

FinInvestment::FinInvestment(QString title, int principal,
                             QDate startDate, int investmentOptionVectorIndex)
    : m_title(title)
    , m_principal(principal)
    , m_startDate(startDate)
    , m_investmentOptionVectorIndex(investmentOptionVectorIndex)
    , m_orderIndex(-1)
{
}

FinInvestment::FinInvestment(const FinInvestment& investment)
    : m_title(investment.m_title)
    , m_principal(investment.m_principal)
    , m_startDate(investment.m_startDate)
    , m_investmentOptionVectorIndex(
            investment.m_investmentOptionVectorIndex)
    , m_orderIndex(investment.m_orderIndex)
{
}

FinInvestment::~FinInvestment()
{
}

void FinInvestment::assign(FinInvestment investment)
{
    this->m_title = investment.m_title;
    this->m_principal =  investment.m_principal;
    this->m_startDate = investment.m_startDate;
    this->m_investmentOptionVectorIndex =
            investment.m_investmentOptionVectorIndex;
    this->m_orderIndex = investment.m_orderIndex;
}

/*
 Getters and Setters
 */
bool FinInvestment::isSimpleInterest()
{
    return investmentOptionVector.at(m_investmentOptionVectorIndex).
            simpleInterest;
}

QDate FinInvestment::startDate()
{
    return m_startDate;
}

void FinInvestment::setStartDate(QDate startDate)
{
    this->m_startDate = startDate;
}

QString FinInvestment::title()
{
    return this->m_title;
}

void FinInvestment::setTitle(QString title)
{
    this->m_title = title;
}

int FinInvestment::durationYears()
{
    return investmentOptionVector.at(
            m_investmentOptionVectorIndex).durationYears;
}

int FinInvestment::principal()
{
    return this->m_principal;
}

void FinInvestment::setPrincipal(int principal)
{
    this->m_principal = principal;
}

double FinInvestment::expectedAnnualGrowth()
{
    return investmentOptionVector.at(
            m_investmentOptionVectorIndex).annualPercentageReturn;
}

double FinInvestment::standardDeviation()
{
    return investmentOptionVector.at(
            m_investmentOptionVectorIndex).standardDeviation;
}

void FinInvestment::setInvestmentOptionVectorIndex(
        int investmentOptionVectorIndex)
{
    this->m_investmentOptionVectorIndex = investmentOptionVectorIndex;
}

int FinInvestment::investmentOptionVectorIndex()
{
    return m_investmentOptionVectorIndex;
}

void FinInvestment::setOrderIndex(int orderIndex)
{
    this->m_orderIndex = orderIndex;
}

int FinInvestment::orderIndex()
{
    return m_orderIndex;
}
